<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width = device-width, initial-scale = 1.0, minimum-scale = 1.0, maximum-scale = 1.0, user-scalable = no"/>
<title>cookie演示例子</title>
</head>
<style>
    body{padding:10px;}
    </style>
<body>

<button id="show_all">显示所有cookie的key值</button>
<br/><br/>
<button id="get_val">弹出test1的值</button>
<br/><br/>
<button id="has_key">弹出cookie里是否有test2这个key</button>
<br/><br/>
<button id="set_item">设置cookie的key为test1值为cat,不填域名</button>
<br/><br/>
<button id="del_all">删除所有cookie</button>
  

<script src="wsj-cookie.js"></script>
<script>
/**
 * 本cookie框架已将默认路径设为根目录,即"/"
 */
docCookies.setItem('test1', '111')//有效期默认到浏览器关闭。未写路径则代表当前目录，建议都写根目录。如果当前是二级域名,则默认用二级域名
docCookies.setItem('test2', 'aaa', 99999)//99999的单位是秒
docCookies.setItem('test3', 'bbb', docCookies.addTime({ year: 1 }))//除了秒,还可以用时间类型
docCookies.setItem('test4', 'ccc', 99999, '/')
docCookies.setItem('test5', 'ddd', 86400, '/', 'gitee.io')//指定了域名后,如需删除该cookie,也要指定相同的域名,下同.
docCookies.setItem('test6', 'eee', 86400, '/', '.gitee.io')
docCookies.setItem('test7', 'fff', 86400, '/', 'sin911.gitee.io')
docCookies.setItem('test8', 'hhh', 86400, '/', '.sin911.gitee.io')
docCookies.setItem('test9', 'ggg', 86400, '/', 'sin911.gitee.io', true)//只有在https环境下才会设置或删除成功


document.getElementById('show_all').onclick = function () {
    alert('Array:'+docCookies.keys())
}

document.getElementById('get_val').onclick = function () {
    alert(docCookies.getItem('test1'))
}

document.getElementById('has_key').onclick = function () {
    alert(docCookies.hasKey('test2'))
}

document.getElementById('set_item').onclick = function () {
    docCookies.setItem('test1', 'cat', 99999)//99999的单位是秒
    alert('设置完成')
}

document.getElementById('del_all').onclick = function () {
    docCookies.removeItem('test1');
    docCookies.removeItem('test2');
    docCookies.removeItem('test3');
    docCookies.removeItem('test4');
    docCookies.removeItem('test5', '/', 'gitee.io');
    docCookies.removeItem('test6', '/', 'gitee.io');
    docCookies.removeItem('test7', '/', 'sin911.gitee.io');
    docCookies.removeItem('test8', '/', 'sin911.gitee.io');
    docCookies.removeItem('test9', '/', 'sin911.gitee.io');
    alert('已全部删除')
}
</script>
</body>
</html>
